function info(customerId,tenantId) {
    var url = "/customer/customerInfo/info.do?customerId=" + customerId+"&tenantId="+tenantId;
    Common.openDlg(url, "用户详情");
}
function updateStauts(customerId,status) {
    var url = "/customer/customerInfo/info.do?customerId=" + customerId+"&status="+status;
    Common.openDlg(url, "用户详情");
}
function order(transactionId){
    window.parent.addTab1("订单详情","./trans/finTransaction/details.do?transactionId=" + transactionId,"transactionId"+transactionId);
}
layui.define(['form', 'laydate', 'table'], function (exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var customerInfoTable = null;
    var view = {
        init: function () {
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function () {
                Lib.doSearchForm($("#searchForm"), customerInfoTable)
            }
        },
        initTable: function () {
            var data = $("#searchForm").serializeJson();
            customerInfoTable = table.render({
                elem: '#customerInfoTable',
                height: Lib.getTableHeight(0),
                cellMinWidth: 100,
                method: 'post',
                where:data,
                url: Common.ctxPath + '/customer/customerInfo/memberList.json' // 数据接口
                , page: Lib.tablePage // 开启分页
                , limit: 10,
                cols: [[ // 表头
                    {
                        type: 'checkbox',
                        fixed: 'left',
                    },
                    {

                        field: 'wxPicurl',
                        title: '头像',
                        templet:function (d) {
                            if(d.wxPicurl){
                                return "<div><img src='"+d.wxPicurl+"' class='laytable-cell-1-wxPicurl'/></div>";
                            }else{
                                return "";
                            }
                        }
                    },
                    {
                        field: 'customerName',
                        title: '姓名',
                    },
                    {

                        field: 'sourceId',
                        title: '手机号',
                    },
                    {
                        field: 'rolesName',
                        title: '会员类型',
                    },
                    {
                        field: 'registerTime',
                        title: '注册时间',
                        width : 170,
                    },
                    {
                        field: 'custStatus',
                        title: '状态',
                        templet: '<div>{{d.custStatus==0?"禁用":"启用"}}</div>'
                    },
                    {

                        field: '',
                        title: '操作',
                        templet: function (d) {
                            return  '<a href="javascript:info(\''+d.customerId+'\','+d.tenantId+')" class="layui-table-link">详情</a>';
                        }
                    },


                ]]

            });
            table.on('sort(customerInfoTable)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                // console.log(obj.field); //当前排序的字段名
                // console.log(obj.type); //当前排序类型：desc（降序）、asc（升序）、null（空对象，默认排序）
                // console.log(this); //当前排序的 th 对象

                //尽管我们的 table 自带排序功能，但并没有请求服务端。
                //有些时候，你可能需要根据当前排序的字段，重新向服务端发送请求，从而实现服务端排序，如：
                table.reload('customerInfoTable', {
                    initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。 layui 2.1.1 新增参数
                    , where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                        field: obj.field //排序字段
                        , order: obj.type //排序方式
                    }
                });
            });
            table.on('checkbox(customerInfoTable)', function (obj) {
                var customerInfo = obj.data;
                if (obj.checked) {
                    //按钮逻辑Lib.buttonEnable()
                } else {

                }
            })
        },

        initSearchForm: function () {
            Lib.initSearchForm($("#searchForm"), customerInfoTable, form);
        },
        initToolBar: function () {
            toolbar = {
                login:function () {
                    // var data = Common.getOneFromTable(table,"customerInfoTable");
                    // if(data==null){
                    //     return ;
                    // }
                    // var origin = window.location.origin
                    // var customerId = data.customerId
                    // var url="";
                    // if(origin.indexOf("qitian.51sdx.com")>=0){
                    //     url = "http://m.51sdx.com/p/qtwlh5s?customerId="+customerId;
                    // }else if(origin.indexOf("cms.51sdx.com")>=0){
                    //     if(data.channel == "GSW001"){
                    //         url = "http://m.51sdx.com/p/gswh5?customerId="+customerId;
                    //     }else{
                    //         url = "http://m.51sdx.com/p/choice?customerId="+customerId;
                    //     }
                    // }else{
                    //     url = "http://m.51sdx.com/t/choice?customerId="+customerId;
                    // }
                    // // window.open(url);
                    // CopyToClipboard(url);
                    var data = Common.getOneFromTable(table,"customerInfoTable");
                    if(data==null){
                        return ;
                    }
                    $.ajax({
                        type: 'POST',
                        url: Common.ctxPath+"/customer/customerInfo/login.json",
                        data: {
                            customerId:data.customerId
                        },
                        dataType:'json',
                        success: function(res){
                            console.log(res);
                            if(res.code==0){
                                var url = res.data.loginPath+"/autoLogin?customerToken="+res.data.customerToken;
                                window.open(url);
                            }
                        }
                    });

                },
                h5login:function () {
                    var data = Common.getOneFromTable(table,"customerInfoTable");
                    if(data==null){
                        return ;
                    }
                    $.ajax({
                        type: 'POST',
                        url: Common.ctxPath+"/customer/customerInfo/login.json",
                        data: {
                            customerId:data.customerId,
                            type:2
                        },
                        dataType:'json',
                        success: function(res){
                            if(res.code==0){
                                var url = res.data.loginPath+"/est/autoLogin?customerToken="+res.data.customerToken;
                                window.open(url);
                            }
                        }
                    });

                },
                status:function () {
                    var data = Common.getOneFromTable(table, "customerInfoTable");
                    if (data == null) {
                        return;
                    }
                    layer.open({
                        type:2
                        ,title:"用户状态"
                        ,area:['300px','200px']
                        ,content:[Common.ctxPath+'/customer/customerInfo/updateStatus.do?customerId='+data.customerId]

                    })
                }
            };
            $('.ext-toolbar').on('click', function () {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
    }

    exports('index', view);

});
